package com.example.springboot.controller;

import com.example.springboot.Result;
import com.example.springboot.domain.User;
import com.example.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UseController {
    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public Result add(@RequestBody User user) {
        userService.add(user);
        return Result.success();
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        User user = userService.selectById(id);
        return Result.success(user);
    }


    @PutMapping("/update")
    public Result updateById(@RequestBody User user) {
        userService.updateUser(user);
        System.out.println(user);
        return Result.success();
    }

}
